package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.system.domain.OtherBlocketRecord;
import com.ruoyi.system.domain.OthertoptaskConfig;
import com.ruoyi.system.mapper.OtherBlockedRecordMapper;
import com.ruoyi.system.mapper.OthertoptaskConfigMapper;
import com.ruoyi.system.service.IOtherBlockedRecordService;
import com.ruoyi.system.service.IOthertoptaskConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@DataSource(value = DataSourceType.SLAVE)
public class OthertoptaskConfigServiceImpl extends ServiceImpl<OthertoptaskConfigMapper, OthertoptaskConfig> implements IOthertoptaskConfigService {

    @Resource
    OthertoptaskConfigMapper othertoptaskConfigMapper;

    @DataSource(value = DataSourceType.SLAVE)
    public List<OthertoptaskConfig> getOthertoptaskConfigList(String roomId) {
        List<OthertoptaskConfig> othertoptaskConfigs = othertoptaskConfigMapper.selectList(new LambdaQueryWrapper<OthertoptaskConfig>().eq(OthertoptaskConfig::getRoomID, roomId));

        boolean hasXinFlag = false;
        for (OthertoptaskConfig othertoptaskConfig : othertoptaskConfigs) {
            if (othertoptaskConfig.getToptaskName().equals("新人置顶")) {
                hasXinFlag = true;
                break;
            }
        }
        if (!hasXinFlag) {
            //创建一个新人置顶卡内容
            OthertoptaskConfig othertoptaskConfignew = new OthertoptaskConfig();
            othertoptaskConfignew.setRoomID(roomId);
            othertoptaskConfignew.setToptaskName("新人置顶");
            othertoptaskConfignew.setNeedCardFlag("1");
            othertoptaskConfignew.setEnableDailyLimit("0");
            othertoptaskConfignew.setDailyLimit("0");
            othertoptaskConfignew.setCardExpirationDays("0");
            othertoptaskConfignew.setJoinRoomBonusQuality("0");
            othertoptaskConfigMapper.insert(othertoptaskConfignew);
            othertoptaskConfigs = othertoptaskConfigMapper.selectList(new LambdaQueryWrapper<OthertoptaskConfig>().eq(OthertoptaskConfig::getRoomID, roomId));
        }

        return othertoptaskConfigs;
    }


    @DataSource(value = DataSourceType.SLAVE)
    public int updateOthertoptaskConfig(OthertoptaskConfig othertoptaskConfig) {
        return othertoptaskConfigMapper.updateById(othertoptaskConfig);
    }


}
